/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sad;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import net.aksingh.java.api.owm.DailyForecastData;
import net.aksingh.java.api.owm.OpenWeatherMap;
import org.json.JSONException;

/**
 *
 * @author paolo
 */
@Named(value = "test")
@RequestScoped
public class NewSessionBean {

    private String city;
    @EJB

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }
    
    public String test() throws IOException, MalformedURLException, JSONException{
        //questo bellissimo numero lo ottente registrandovi sul sito di openweathermap o potete usare questo
        OpenWeatherMap owm = new OpenWeatherMap("475f2d874b5b1aded3861c7e7407f761");
        //numero di giorni di cui si vogliono le previsioni
        byte count = 6;
        List<DailyForecastData.Forecast> forecast_List = owm.dailyForecastByCityName(city, count).getForecast_List();      
        for (DailyForecastData.Forecast forecast_List1 : forecast_List) {
            System.out.println(city+" "+forecast_List1.getDateTime()+" "+forecast_List1.getTemperature_Object().getMaximumTemperature()+" "+forecast_List1.getTemperature_Object().getMinimumTemperature());
            List<DailyForecastData.Forecast.Weather> weather_List = forecast_List1.getWeather_List();
            for (DailyForecastData.Forecast.Weather weather_List1 : weather_List) {
                System.out.println(weather_List1.getWeatherCode()+" "+weather_List1.getWeatherDescription());
            }
        }
        return "index";
        
    }
}
